home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / bipl.zip / PROGS.ZIP / DEAL.ICN < prev    next >
Text File  |  1992-09-28  |  3KB  |  117 lines

  1. ############################################################################
  2. #
  3. #    File:     deal.icn
  4. #
  5. #    Subject:  Program to deal bridge hands
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     June 10, 1988
  10. #
  11. ###########################################################################
  12. #  
  13. #     This program shuffles, deals, and displays hands in the game
  14. #  of bridge.  An example of the output of deal is
  15. #       ---------------------------------
  16. #  
  17. #                 S: KQ987
  18. #                 H: 52
  19. #                 D: T94
  20. #                 C: T82
  21. #  
  22. #       S: 3                S: JT4
  23. #       H: T7               H: J9863
  24. #       D: AKQ762           D: J85
  25. #       C: QJ94             C: K7
  26. #  
  27. #                 S: A652
  28. #                 H: AKQ4
  29. #                 D: 3
  30. #                 C: A653
  31. #  
  32. #       ---------------------------------
  33. #  
  34. #  Options: The following options are available:
  35. #  
  36. #       -h n Produce n hands. The default is 1.
  37. #  
  38. #       -s n Set the seed for random generation to n.  Different
  39. #            seeds give different hands.  The default seed is 0.
  40. #  
  41. ############################################################################
  42. #
  43. #  Links: options, shuffle
  44. #
  45. ############################################################################
  46.  
  47. link options, shuffle
  48.  
  49. global deck, deckimage, handsize, suitsize, denom, rank, blanker
  50.  
  51. procedure main(args)
  52.    local hands, opts
  53.  
  54.    deck := deckimage := string(&letters)    # initialize global variables
  55.    handsize := suitsize := *deck / 4
  56.    rank := "AKQJT98765432"
  57.    blanker := repl(" ",suitsize)
  58.    denom := &lcase[1+:suitsize]
  59.  
  60.    opts := options(args,"h+s+")
  61.    hands := \opts["h"] | 1
  62.    &random := \opts["s"]
  63.  
  64.    every 1 to hands do
  65.       display()
  66.  
  67. end
  68.  
  69. #  Display the hands
  70. #
  71. procedure display()
  72.    local layout, i
  73.    static bar, offset
  74.  
  75.    initial {
  76.       bar := "\n" || repl("-",33)
  77.       offset := repl(" ",10)
  78.       }
  79.  
  80.    deck := shuffle(deck)
  81.    layout := []
  82.    every push(layout,show(deck[(0 to 3) * handsize + 1 +: handsize]))
  83.  
  84.    write()
  85.    every write(offset,!layout[1])
  86.    write()
  87.    every i := 1 to 4 do
  88.       write(left(layout[4][i],20),layout[2][i])
  89.    write()
  90.    every write(offset,!layout[3])
  91.    write(bar)
  92. end
  93.  
  94. #  Put the hands in a form to display
  95. #
  96. procedure show(hand)
  97.    static clubmap, diamondmap, heartmap, spademap
  98.    initial {
  99.       clubmap := denom || repl(blanker,3)
  100.       diamondmap := blanker || denom || repl(blanker,2)
  101.       heartmap := repl(blanker,2) || denom || blanker
  102.       spademap := repl(blanker,3) || denom
  103.       }
  104.    return [
  105.       "S: " || arrange(hand,spademap),
  106.       "H: " || arrange(hand,heartmap),
  107.       "D: " || arrange(hand,diamondmap),
  108.       "C: " || arrange(hand,clubmap)
  109.       ]
  110. end
  111.  
  112. #  Arrange hands for presentation
  113. #
  114. procedure arrange(hand,suit)
  115.    return map(map(hand,deckimage,suit) -- ' ',denom,rank)
  116. end
  117.